import java.util.HashMap;

public class StudentHashMap {
    private String name;
    private int age;

    public StudentHashMap() {
    }

    public StudentHashMap(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "StudentHashMap{name = " + name + ", age = " + age + "}";
    }


    public static void main(String[] args) {
        //创建一个HashMap
        HashMap<StudentHashMap, String> hm = new HashMap<>();

        //创建三个StudentHashMap对象
        StudentHashMap s1 = new StudentHashMap("张三", 20);
        StudentHashMap s2 = new StudentHashMap("李四", 22);
        StudentHashMap s3 = new StudentHashMap("王五", 21);
        //将StudentHashMap对象添加到HashMap中
        hm.put(s1, "北京");
        hm.put(s2, "上海");
        hm.put(s3, "广州");
        //打印HashMap
        System.out.println(hm);
        //增强for遍历
        System.out.println("增强for遍历");
        for (StudentHashMap key : hm.keySet()) {
            System.out.println(key.getName() + "---" + hm.get(key));
        }

        //Lambda遍历
        System.out.println("Lambda遍历");
        hm.forEach((studentHashMap, s) -> System.out.println(studentHashMap.getName() + "---" + s));
    }
}
